﻿using MediatR;
using SystemMHB.API.Application.Command.ProcessTaskCommand;
using SystemMHB.Domian;
using SystemMHB.Infrstructer.Interface;

namespace SystemMHB.API.Application.CommandHandlers.ProcessTaskCommandHandler
{
    public class ProcessTaskAddCommandHandler:IRequestHandler<ProcessTaskAddCommand,int>
    {
        /// <summary>
        /// 工序任务仓储接口
        /// </summary>
        IProcessTaskRepository _process;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_process">工序任务仓储接口</param>
        public ProcessTaskAddCommandHandler(IProcessTaskRepository _process)
        {
            this._process = _process;
        }

        public async Task<int> Handle(ProcessTaskAddCommand request, CancellationToken cancellationToken)
        {
            request.AddName = "张三";
            request.AddTime=DateTime.Now.ToUniversalTime();
            return await _process.AddAsync(new Domian.ProcessTask()
            {
                processTaskId=request.processTaskId,
                taskMumber = request.taskMumber,
                taskStatus = request.taskStatus,
                priority = request.priority,
                productionLot = request.productionLot,
                processName = request.processName,
                finishedNumber = request.finishedNumber,
                AddName = request.AddName,
                AddTime = request.AddTime,
                workOrder=request.workOrder,
                size = request.size,
                unit = request.unit,
                specifications = request.specifications,
                IsDel =request.IsDel
            });
        }
    }
}
